function useFixedHeader() {
  const html = document.querySelector("html")!;
  return (id?: string) => {
    if (!id) {
      const [_, hid] = window.location.href.split("#").map((s) => decodeURI(s));
      id = hid;
    }

    const element = document.getElementById(id as string);
    if (window.innerWidth < 382) {
      element &&
        html.scrollTo({
          top: element.offsetTop + 14,
          behavior: "smooth",
        });
    } else if (window.innerWidth < 992) {
      element &&
        html.scrollTo({
          top: element.offsetTop + 118,
          behavior: "smooth",
        });
    } else {
      element &&
        html.scrollTo({
          top: element.offsetTop + 40,
          behavior: "smooth",
        });
    }
  };
}

export default useFixedHeader;
